package com.okyai.kt.service.impl;

import java.util.List;
import com.okyai.common.utils.DateUtils;
import com.okyai.common.utils.ShiroUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.okyai.kt.mapper.DemographyMapper;
import com.okyai.kt.domain.Demography;
import com.okyai.kt.service.IDemographyService;
import com.okyai.common.annotation.DataScope;
import com.okyai.common.core.domain.entity.SysUser;
import com.okyai.common.core.text.Convert;

/**
 * 人口学Service业务层处理
 * 
 * @author okyai
 * @date 2021-03-20
 */
@Service
public class DemographyServiceImpl implements IDemographyService 
{
    @Autowired
    private DemographyMapper demographyMapper;

    /**
     * 查询人口学
     * 
     * @param demographyId 人口学ID
     * @return 人口学
     */
    @Override
    public Demography selectDemographyById(Long demographyId)
    {
        return demographyMapper.selectDemographyById(demographyId);
    }

    /**
     * 查询人口学列表
     * 
     * @param demography 人口学
     * @return 人口学
     */
    @Override
    @DataScope(deptAlias = "d",userAlias = "t")
    public List<Demography> selectDemographyList(Demography demography)
    {
        return demographyMapper.selectDemographyList(demography);
    }

    /**
     * 新增人口学
     * 
     * @param demography 人口学
     * @return 结果
     */
    @Override
    public int insertDemography(Demography demography)
    {
    	SysUser user = ShiroUtils.getSysUser();
    	demography.setCreateBy(user.getUserName());
    	demography.setUserId(user.getUserId());
    	//暂时吧部门ID设置为租户
    	demography.setDeptId(user.getDeptId());
        demography.setCreateTime(DateUtils.getNowDate());
        return demographyMapper.insertDemography(demography);
    }

    /**
     * 修改人口学
     * 
     * @param demography 人口学
     * @return 结果
     */
    @Override
    public int updateDemography(Demography demography)
    {
        demography.setUpdateTime(DateUtils.getNowDate());
        return demographyMapper.updateDemography(demography);
    }

    /**
     * 删除人口学对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteDemographyByIds(String ids)
    {
        return demographyMapper.deleteDemographyByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除人口学信息
     * 
     * @param demographyId 人口学ID
     * @return 结果
     */
    @Override
    public int deleteDemographyById(Long demographyId)
    {
        return demographyMapper.deleteDemographyById(demographyId);
    }
}
